/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import data.model.Flight;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author zhenia
 */
public class MyTableModel extends AbstractTableModel {

    private String[] columnNames = {"Route", "Airline", "Cost", "Departure time",
        "Arrival time", "Capacity", "Airplane", "Flight"};
    private Object[][] data;

    public MyTableModel(List<Flight> flights) {
        data = new Object[flights.size()][columnNames.length];

        for (int i = 0; i < flights.size(); i++) {
            data[i][2] = flights.get(i).getCost();
            data[i][1] = flights.get(i).getAirline().getName();
            data[i][0] = flights.get(i).getRoute().toString();
            data[i][3] = flights.get(i).getDepartureTime();
            data[i][4] = flights.get(i).getArrivalTime();
            data[i][5] = flights.get(i).getAirplane().getSeats();
            data[i][6] = flights.get(i).getAirplane().getModel();
            data[i][7] = flights.get(i).getCode();
        }
    }

    MyTableModel() {
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        return data.length;
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        return data[row][col];
    }
}
